package com.zyp.test.test;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import com.squareup.picasso.Picasso;

/**
 * Created by zyp on 2017/9/14.
 */

public class ListViewAdapter extends BaseAdapter {
    private String test = "";
    private Context mContext;
    private List<String> mUrls;
    private ViewHolder mViewHolder;
    ListViewAdapter(Context context, List<String> urls){
        mContext = context;
        mUrls = urls;
    }
    @Override
    public int getCount() {
        return mUrls.size();
    }

    @Override
    public Object getItem(int position) {
        return mUrls.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_listview,null);
            mViewHolder = new ViewHolder() ;
            mViewHolder.mCircleImageView = (CircleImageView) convertView.findViewById(R.id.cv_icon);
            convertView.setTag(mViewHolder);
        }else {
            mViewHolder = (ViewHolder) convertView.getTag();
        }
        Picasso.with(mContext).load(mUrls.get(position)).placeholder(R.mipmap.ic_launcher).into(mViewHolder.mCircleImageView);
        return convertView;
    }
    private class ViewHolder{
        CircleImageView mCircleImageView;
    }
}
